package com.echo.register.user.api;

import com.echo.register.common.result.Result;
import com.echo.register.user.service.UserInfoService;
import com.echo.register.user.utils.ConstantPropertiesUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: WeixinApiController
 * @Package: com.echo.register.user.api
 * @Description:
 * @Author 谢同学
 * @Create 2023/12/31 17:22
 * @Version 1.0
 */
@Api(tags = "微信登录")
@RestController
@RequestMapping("/api/ucenter/wx")
public class WeixinApiController {
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("getLoginParam")
    @ApiOperation("获取微信登录参数")
    public Result genQrConnect(HttpSession session) throws UnsupportedEncodingException {
        String redirectUri = URLEncoder.encode(ConstantPropertiesUtil.WX_OPEN_REDIRECT_URL, "UTF-8");
        Map<String, Object> map = new HashMap<>();
        map.put("appid", ConstantPropertiesUtil.WX_OPEN_APP_ID); // 应用唯一标识
        map.put("redirectUri", redirectUri);// 重定向地址
        map.put("scope", "snsapi_login"); // 作用域 网页应用目前仅填写snsapi_login
        map.put("state", System.currentTimeMillis()+"");//用于保持请求和回调的状态
        return Result.ok(map);
    }

}
